#pragma once
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/epoll.h>
#include<assert.h>
#include<iostream>
#include<chrono>
#include<map>
#include<atomic>
#include"Timer.h"
#include"ThreadPool.hpp"

using time_point = std::chrono::system_clock::time_point;

class DealConn{
public:
  static void addfd(int fd);
  static void resetfd(int fd);
  static void et(epoll_event* events, int number, int listenfd);
  static void start();
  static void flushTime(int fd, bool isOver);
  static void closeConn(const int &fd);
  static void freefd(int fd);
  static void setTime(int fd, time_point &&t);
private:
  static std::chrono::duration<int,std::ratio<10>> maxLiveTime;
  static std::map<int, time_point> lastActTimes;
  static ThreadPool<int> reqs;
  static ThreadPool<int> rets;
  static Timer timer;
  static int epollfd;
  static std::atomic_flag lock; 
  const static int port = 8090;
  const static int esize = 10;
  const static int size = 4096;
};
